LicPlateNN : License plate detection and recognition
The licplatenn
module provides license plate detection and recognition function.
User can use the following code to import the licplatenn
module.
var licplatenn = require('licplatenn');
Support
The following shows licplatenn
module APIs available for each permissions.
User Mode | Privilege Mode | |
---|---|---|
licplatenn.detect | ● | ● |
licplatenn.identify | ● | ● |
licplatenn Object
licplatenn.detect(videoBuf, attribute)
videoBuf
{Buffer} Video buffer.attribute
{Object} Video attribute.- Returns: {Array} License plate info objects array which detectd.
Detect license plate infos in given video buffer.
The video attribute attribute
object contains the following members:
width
{Integer} Video width.height
{Integer} Video height.pixelFormat
{Integer} Pixel format.
pixelFormat
is a integer, can be:
Value | Description |
---|---|
licplatenn.PIX_FMT_RGB24 | RGB24 pixel format. |
licplatenn.PIX_FMT_BGR2RGB24 | BGR24 to RGB24 pixel format. |
licplatenn.PIX_FMT_GRAY2RGB24 | Grayscale to RGB24 pixel format. |
licplatenn.PIX_FMT_RGBA2RGB24 | RGBA to RGB24 pixel format. |
The returned license plate info object contains the following members:
prob
{Number} Probability0.0 ~ 1.0
.x0
{Integer} x position of upper left corner.y0
{Integer} y position of upper left corner.x1
{Integer} x position of lower right corner.y1
{Integer} y position of lower right corner.
licplatenn.identify(videoBuf, attribute, licPlateInfo)
videoBuf
{Buffer} Video buffer.attribute
{Object} Video attribute.licPlateInfo
{Object} License plate info object.- Returns: {String} License plate number.
Identify license plate number of given license plate info.
Example
This example show how to detect and identify license plate.
var MediaDecoder = require('mediadecoder');
var iosched = require('iosched');
var licplatenn = require('licplatenn');
var image = new MediaDecoder().open('file://./1.jpg');
var fmt = image.srcVideoFormat();
image.destVideoFormat({width: fmt.width, height: fmt.height, fps: 1, pixelFormat: MediaDecoder.PIX_FMT_RGB24, noDrop: false, disable: false});
image.destAudioFormat({disable: true});
image.previewFormat({enable: true, fb: 0, fps: 25, fullscreen: false});
var ol = image.overlay();
var quited = false;
image.on('video', (video) => {
var buf = new Buffer(video.arrayBuffer);
var licInfo = licplatenn.detect(buf, {width: fmt.width, height: fmt.height, pixelFormat: licplatenn.PIX_FMT_RGB24});
ol.clear();
if (licInfo.length) {
ol.font(12);
for (var i = 0; i < licInfo.length; i++) {
var licNum = licplatenn.identify(buf, {width: fmt.width, height: fmt.height, pixelFormat: licplatenn.PIX_FMT_RGB24}, licInfo[i])
ol.rect(licInfo[i].x0, licInfo[i].y0, licInfo[i].x1, licInfo[i].y1, MediaDecoder.C_GREEN, 2, 0, false);
ol.text(licInfo[i].x0, licInfo[i].y0 - 30, licNum, MediaDecoder.C_GREEN);
}
}
});
image.on('eof', () => {
quited = true;
});
image.start();
while (!quited) {
iosched.poll(); // Event poll.
}
image.close();